import logging

import allure
import jsonpath

from utils.launch_request import launch_jdbc_Request


def json_extractor(case,all,res):
    if case["jsonExData"]:
        with allure.step("json 提取"):
            for key, value in eval(case["jsonExData"]).items():
                value = jsonpath.jsonpath(res.json(), value)[0]
                all[key] = value
                # print(case["jsonExData"])
                # print(all)
            logging.info(f'4.json提取：根据{case["jsonExData"]}提取数据，全局变量为：{all}')
            allure.attach(f'4.json提取：根据{case["jsonExData"]}提取数据，全局变量为：{all}",name="json提取数据结果')





def sql_extractor(case,all):
    if case["sqlExData"]:
        with allure.step("jdbc 提取"):
            for key, value in eval(case["sqlExData"]).items():
                all[key] = launch_jdbc_Request(value)
                # print(all)
            logging.info(f'4.jdbc提取：根据{case["sqlExData"]}提取数据，全局变量为：{all}')
            allure.attach(f'4.jdbc提取：根据{case["sqlExData"]}提取数据，全局变量为：{all}",name="jdbc提取数据结果')


